$(function () {
        //头部导航的简单效果
    $(".hnavr").children("li").on("mouseenter",function () {
        if($(this).find("div")[0]){
        $(this).css("background","white").siblings("li").css("background","#f2f2f2").end().children("div").css("display","block").end().siblings("li").children("div").css("display","none");
        $(this).find("span").css("display","none").parents("li").siblings().find("span").css("display","block")
        $(this).next().find("span").css("display","none");
        }
        })
    $(".hnavr").children("li").on("mouseleave",function () {
        $(this).css("background","#f2f2f2").find("div").css("display","none").parents("li").find("span").css("display","block")
    })
    $("#search")[0].placeholder="面膜";
    $("#search").on("focus",function () {
        $("#search")[0].placeholder="";
    })
    $("#search").on("blur",function () {
        $("#search")[0].placeholder="面膜";
    })


        //免登入与登入
    var tempstr=$.cookie("mylogin");
    if(tempstr){
        $('#e-mail').val(JSON.parse(tempstr).umail);
        $('#code').val(JSON.parse(tempstr).upwd);
    }
    var tempstr=$.cookie("mylogin");
    if(tempstr){
        $(".hnavl").children("li").eq(1).text("您好："+JSON.parse(tempstr).umail);
        $(".hnavl").children("li").eq(2).text("退出");

        $(".hnavl").children("li").eq(2).on("click",function () {
            $(".hnavl").children("li").eq(1).text("")
            $(".hnavl").children("li").eq(2).text("")
            $("<a href=\"login.html\">登入</a>").appendTo($(".hnavl").children("li").eq(1))
            $("<a href=\"reg.html\">免费注册</a><span></span>").appendTo($(".hnavl").children("li").eq(2))
        })
    }
    $("#loginbtn1").on("click",function() {
        console.log(1);
        $.ajax({
            type: "post",
            url: "http://localhost/project/login1.php",
            async: true,
            data: $.toObject($("#myinfo").serialize()),
            success: function (res) {
                console.log(2);
                if ($(".freelogin").eq(1).find("input[type='checkbox']")[0].checked) {
                    $.cookie('mylogin', JSON.stringify($.toObject($("#myinfo").serialize())), {expires: 7})
                }
            }
        });
    })
    //x写二级三级导航
    var subimgArr =["url('img/img-code/subnav0.png')","url('img/img-code/subnav1.png')","url('img/img-code/subnav2.png')","url('img/img-code/subnav3.png')","url('img/img-code/subnav4.png')","url('img/img-code/subnav5.png')","url('img/img-code/subnav6.png')","url('img/img-code/subnav7.png')","url('img/img-code/subnav8.png')","url('img/img-code/subnav9.png')","url('img/img-code/subnav10.png')"]
    var sublistArr =["母婴儿童","美容彩妆","服饰鞋包","家居个护","营养保健","海外直邮","数码家电","环球美食","户外运动","水果生鲜","药品物资"]
    for(var i=0;i<$("#subnav>div").length;i++){
        $("#subnav>div").eq(i).css("background-image",subimgArr[i])
        $("#subnav>div")[i].innerHTML+=sublistArr[i];
    }
    $("<i class='iconfont icon-2'></i>").prependTo($("#subnav>div"))
    //填写三级导航内容

    var dArr=["牛肉","牛排","其他肉类","鸡肉产品","鸡蛋","猪肉","腊肠","火腿","驴肉","火锅食材"];
    var fishArr = ["鱼类/三文鱼","虾类","大闸蟹","其他水产","海参","贝类","螃蟹","海鲜礼盒","鱼类制品","乌贼","大闸蟹礼券"];
    var cArr = ["冷冻食品","冷冻面点","海鲜制品","奶制品","蛋糕面包","冰淇淋","其他冷冻食品"]
    var fArr=["火龙果","奇异果","榴莲","柠檬","牛油果","苹果","橙子","其他水果","柚子","枣梨","石榴","龙眼"]
    for(var j=0;j<9;j++){
    for(var i=0;i<fArr.length;i++){
        $("<li><a href='#'>"+fArr[i]+"</a><span></span></li>").appendTo($("#subnav").children("div").eq(j).find(".box").eq(0).children("ul"));
    }
    for(var i=0;i<dArr.length;i++){
        $("<li><a href='#'>"+fArr[i]+"</a><span></span></li>").appendTo($("#subnav").children("div").eq(j).find(".box").eq(1).children("ul"));
    }
    for(var i=0;i<fishArr.length;i++){
        $("<li><a href='#'>"+fArr[i]+"</a><span></span></li>").appendTo($("#subnav").children("div").eq(j).find(".box").eq(2).children("ul"));
    }
    for(var i=0;i<cArr.length;i++){
        $("<li><a href='#'>"+fArr[i]+"</a><span></span></li>").appendTo($("#subnav").children("div").eq(j).find(".box").eq(3).children("ul"));
    }
    for(var i=0;i<$(".box").length;i++){
        $("#subnav").children("div").eq(j).find(".box").eq(i).find("li:last").children("span").remove()
    }
    if($("#subnav").children("div").eq(j).find(".box").eq(4)){
        for(var i=0;i<cArr.length;i++){
            $("<li><a href='#'>"+fArr[i]+"</a><span></span></li>").appendTo($("#subnav").children("div").eq(j).find(".box").eq(4).children("ul"));
        }
    }
        if($("#subnav").children("div").eq(j).find(".box").eq(5)){
            for(var i=0;i<cArr.length;i++){
                $("<li><a href='#'>"+fArr[i]+"</a><span></span></li>").appendTo($("#subnav").children("div").eq(j).find(".box").eq(5).children("ul"));
            }
        }
    }

    var trdrArr=[
        ["img/img-code/q11.jpg","img/img-code/q12.jpg","img/img-code/q13.jpg","img/img-code/q14.jpg","img/img-code/q15.jpg","img/img-code/q16.jpg","img/img-code/q17.jpg","img/img-code/q18.jpg","img/img-code/q19.jpg"],
        ["img/img-code/q21.jpg","img/img-code/q22.jpg","img/img-code/q23.jpg","img/img-code/q24.jpg","img/img-code/q25.jpg","img/img-code/q26.jpg","img/img-code/q27.jpg","img/img-code/q28.jpg","img/img-code/q29.jpg"],
        ["img/img-code/q31.jpg","img/img-code/q32.jpg","img/img-code/q33.jpg","img/img-code/q34.jpg","img/img-code/q35.jpg","img/img-code/q36.jpg","img/img-code/q37.jpg","img/img-code/q38.jpg","img/img-code/q39.jpg"],
        ["img/img-code/q41.jpg","img/img-code/q42.jpg","img/img-code/q43.jpg","img/img-code/q44.jpg","img/img-code/q45.jpg","img/img-code/q46.jpg","img/img-code/q47.jpg","img/img-code/q48.jpg","img/img-code/q49.jpg"],
        ["img/img-code/q51.jpg","img/img-code/q52.jpg","img/img-code/q53.jpg","img/img-code/q54.jpg","img/img-code/q55.jpg","img/img-code/q56.jpg","img/img-code/q57.jpg","img/img-code/q58.jpg","img/img-code/q59.jpg"],
        ["img/img-code/q61.jpg","img/img-code/q62.jpg","img/img-code/q63.jpg","img/img-code/q64.jpg","img/img-code/q65.jpg","img/img-code/q66.jpg","img/img-code/q67.jpg","img/img-code/q68.jpg","img/img-code/q69.jpg"],
        ["img/img-code/q71.jpg","img/img-code/q72.jpg","img/img-code/q73.jpg","img/img-code/q74.jpg","img/img-code/q75.jpg","img/img-code/q76.jpg","img/img-code/q77.jpg","img/img-code/q78.jpg","img/img-code/q79.jpg"],
        ["img/img-code/q81.jpg","img/img-code/q82.jpg","img/img-code/q83.jpg","img/img-code/q84.jpg","img/img-code/q85.jpg","img/img-code/q86.jpg","img/img-code/q87.jpg","img/img-code/q88.jpg","img/img-code/q89.jpg"],
        ["img/img-code/trd1.jpg","img/img-code/trd2.jpg","img/img-code/trd3.jpg","img/img-code/trd4.jpg","img/img-code/trd5.jpg","img/img-code/trd6.jpg","img/img-code/trd7.jpg","img/img-code/trd8.jpg","img/img-code/trd9.jpg"]
    ]
    for(var j=0;j<9;j++){
        for(var i=0;i<trdrArr.length;i++){
            $("<li><a href='#'><img src="+trdrArr[j][i]+"></a></li>").appendTo($("#subnav").children("div").eq(j).find(".trdr").children("ul"));
    }
        $("#subnav").children("div").eq(j).find(".trdnav").css("top",-j*32)
    }
   // 二级导航的出现与消失
    $(".btnav").find("li").eq(0).on("mouseenter",function () {
        $(this).find("#subnav").css("display","block")
        //三级导航的出现与消失
        $("#subnav").children("div").on("mouseenter",function () {
            $(this).find(".trdnav").css("display","block")
        })
        $("#subnav").children("div").on("mouseleave",function () {
            $(this).find(".trdnav").css("display","none")
        })
    })
    $(".btnav").find("li").eq(0).on("mouseleave",function () {
        $(this).find("#subnav").css("display","none")
    })

    //★☆99任选3件 ☆★
    var choosebImg = ["img/img-code/nav1.png","img/img-code/japan.png","img/img-code/japan.png","img/img-code/japan.png","img/img-code/nav2.png"]
    var chooseImg = ["img/img-code/chooseany1.jpg","img/img-code/chooseany2.jpg","img/img-code/chooseany3.jpg","img/img-code/chooseany4.jpg","img/img-code/chooseany5.jpg"];
    var choosePt = ["Avène 雅漾 舒护活泉水喷雾 50毫升","SHISEIDO 资生堂 UNO 男士洗面奶 磨砂清凉型 蓝色 130克","SHISEIDO 资生堂 UNO 男士洗面奶 黑炭控油型 130克","SHISEIDO 资生堂 UNO 男士洗面奶 保湿温和型 白色 130克","MEDIHEAL 美迪恵尔 N.M.F水润保湿免洗睡眠面膜膏 15毫升/袋 5袋装"];
    var choosePm = ["酝酿十年只为你","磨砂去角质，洗后清新爽快","清爽洁净皮脂污垢","洗出滋润感","夜晚做个睡美人"];
    var choosePf = ["立减￥50","立减￥65","立减￥66","立减￥66","立减￥97"]
    var choosePp = ["￥55","￥45","￥44","￥44","￥48"]
    for(var i=0;i<$(".chooseany .cul").find("div").length;i++){
        $("<a href='#'><img src="+chooseImg[i]+"></a>").appendTo($(".chooseany .cul").find("div").eq(i))
        $("<img class='scimg' src="+choosebImg[i]+">").appendTo($(".chooseany .cul").find("div").eq(i))
        $("<a href='#'><p>"+choosePt[i]+"</p></a>").appendTo($(".chooseany .cul").find("div").eq(i))
        $("<a href='#'><p>"+choosePm[i]+"</p></a>").appendTo($(".chooseany .cul").find("div").eq(i))
        $("<ul><li>"+choosePf[i]+"</li></ul>").appendTo($(".chooseany .cul").find("div").eq(i))
        $("<span>"+choosePp[i]+"</span>").appendTo($(".chooseany .cul").find("div").eq(i))
        $("<i class='shopping'>加入购物车</i>").appendTo($(".chooseany .cul").find("div").eq(i))
        $("<span>188元选6件</span>").appendTo($(".chooseany .cul").find("div").eq(i))
    }
$("<li>包邮</li>").appendTo($(".chooseany .cul").find("div").eq($(".chooseany .cul").find("div").length-1).find("ul"));
    $(".chooseany #shopping").on("click",function () {

    })
        var index=[]
    $(".shopping").on("click",function () {
       var temp=$(this).parents("div").index()
        if(index.indexOf(temp)!=-1) {
            alert("你已经添加过了")
        }else {
            index.push(temp)
        }
        var a =index.length
        $(".tzshopcar").eq(1).append($("<b>"+a+"</b>"))
    })
    console.log($(".tzshopcar").eq(1));
    $(".tzshopcar").on("click",function () {
        window.open("html/shopping.html?arr="+index)
    })
    //美容彩妆
    $.ajax({
        url:"json/mrcz.json",
        success:function (res) {
            var arrList =res.zone_data[0].showGoodsList
            arrList.forEach(function (value) {
                var tt = value.goods
                $("<div></div>").appendTo($(".beauty .cul"))
                $("<a href='javascript:;'><img src="+tt.imageUrl+"></a>").appendTo($(".beauty .cul").find("div").eq($(".beauty .cul").find("div").length-1))
                $("<img class='scimg' src="+tt.countryCode.flagImage+">").appendTo($(".beauty .cul").find("div").eq($(".beauty .cul").find("div").length-1))
                $("<a href='#'><p>"+tt.title+"</p></a>").appendTo($(".beauty .cul").find("div").eq($(".beauty .cul").find("div").length-1))
                $("<a href='#'><p>"+tt.introduce+"</p></a>").appendTo($(".beauty .cul").find("div").eq($(".beauty .cul").find("div").length-1))
                if(tt.memberPrice) {
                    $("<ul><li>每件" + tt.memberPrice + "元</li></ul>").appendTo($(".beauty .cul").find("div").eq($(".beauty .cul").find("div").length - 1));
                    $("<li>包邮</li>").appendTo($(".beauty .cul").find("div").eq($(".beauty .cul").find("div").length-1).find("ul"));
                }else {
                    $("<ul><li>包邮</li></ul>").appendTo($(".beauty .cul").find("div").eq($(".beauty .cul").find("div").length - 1));
                }
                $("<span>￥"+tt.actualCurrentPrice+"</span>").appendTo($(".beauty .cul").find("div").eq($(".beauty .cul").find("div").length-1))
                $("<i class='gologin'>立即购买</i>").appendTo($(".beauty .cul").find("div").eq($(".beauty .cul").find("div").length-1))
            })
            $(".beauty .cul").children("div").on("click",function () {
                var temp = $(this).index();
                window.open("html/date7.html?json=mrcz.json;Index="+temp);
            })
        }
    })
    //家具个护
    $.ajax({
        url:"json/jjgh.json",
        success:function (res) {
            var arrList =res.zone_data[0].showGoodsList
            arrList.forEach(function (value,index) {
                var tt = value.goods
                $("<div></div>").appendTo($(".furniture .cul"))
                $("<a href='html/date"+index+".html'><img src="+tt.imageUrl+"></a>").appendTo($(".furniture .cul").find("div").eq($(".furniture .cul").find("div").length-1))
                $("<img class='scimg' src="+tt.countryCode.flagImage+">").appendTo($(".furniture .cul").find("div").eq($(".furniture .cul").find("div").length-1))
                $("<a href='#'><p>"+tt.title+"</p></a>").appendTo($(".furniture .cul").find("div").eq($(".furniture .cul").find("div").length-1))
                $("<a href='#'><p>"+tt.introduce+"</p></a>").appendTo($(".furniture .cul").find("div").eq($(".furniture .cul").find("div").length-1))
                    if(tt.memberPrice) {
                        $("<ul><li>每件" + tt.memberPrice + "元</li></ul>").appendTo($(".furniture .cul").find("div").eq($(".furniture .cul").find("div").length - 1));
                        $("<li>包邮</li>").appendTo($(".furniture .cul").find("div").eq($(".furniture .cul").find("div").length-1).find("ul"));
                    }else {
                        $("<ul><li>包邮</li></ul>").appendTo($(".furniture .cul").find("div").eq($(".furniture .cul").find("div").length - 1));
                    }
                $("<span>￥"+tt.actualCurrentPrice+"</span>").appendTo($(".furniture .cul").find("div").eq($(".furniture .cul").find("div").length-1))
                $("<i class='gologin'>立即购买</i>").appendTo($(".furniture .cul").find("div").eq($(".furniture .cul").find("div").length-1))
            })
            $(".furniture .cul").children("div").on("click",function () {
                var temp = $(this).index();
                window.open("html/date7.html?json=jjgh.json;Index="+temp);
            })
        }
    })

    //母婴儿童
    $.ajax({
        url:"json/myet.json",
        success:function (res) {
            var arrList =res.zone_data[0].showGoodsList
            arrList.forEach(function (value) {
                var tt = value.goods
                $("<div></div>").appendTo($(".matherandson .cul"))
                $("<a href='#'><img src="+tt.imageUrl+"></a>").appendTo($(".matherandson .cul").find("div").eq($(".matherandson .cul").find("div").length-1))
                $("<img class='scimg' src="+tt.countryCode.flagImage+">").appendTo($(".matherandson .cul").find("div").eq($(".matherandson .cul").find("div").length-1))
                $("<a href='#'><p>"+tt.title+"</p></a>").appendTo($(".matherandson .cul").find("div").eq($(".matherandson .cul").find("div").length-1))
                $("<a href='#'><p>"+tt.introduce+"</p></a>").appendTo($(".matherandson .cul").find("div").eq($(".matherandson .cul").find("div").length-1))
                if(tt.memberPrice) {
                    $("<ul><li>每件" + tt.memberPrice + "元</li></ul>").appendTo($(".matherandson .cul").find("div").eq($(".matherandson .cul").find("div").length - 1));
                    $("<li>包邮</li>").appendTo($(".matherandson .cul").find("div").eq($(".matherandson .cul").find("div").length-1).find("ul"));
                }else {
                    $("<ul><li>包邮</li></ul>").appendTo($(".matherandson .cul").find("div").eq($(".matherandson .cul").find("div").length - 1));
                }
                $("<span>￥"+tt.actualCurrentPrice+"</span>").appendTo($(".matherandson .cul").find("div").eq($(".matherandson .cul").find("div").length-1))
                $("<i class='gologin'>立即购买</i>").appendTo($(".matherandson .cul").find("div").eq($(".matherandson .cul").find("div").length-1))
            })
            $(".matherandson .cul").children("div").on("click",function () {
                var temp = $(this).index();
                window.open("html/date7.html?json=myet.json;Index="+temp);
            })
        }
    })

    //美食保健
    $.ajax({
        url:"json/msbj.json",
        success:function (res) {
            var arrList =res.zone_data[0].showGoodsList
            arrList.forEach(function (value) {
                var tt = value.goods
                $("<div></div>").appendTo($(".nicefood .cul"))
                $("<a href='#'><img src="+tt.imageUrl+"></a>").appendTo($(".nicefood .cul").find("div").eq($(".nicefood .cul").find("div").length-1))
                $("<img class='scimg' src="+tt.countryCode.flagImage+">").appendTo($(".nicefood .cul").find("div").eq($(".nicefood .cul").find("div").length-1))
                $("<a href='#'><p>"+tt.title+"</p></a>").appendTo($(".nicefood .cul").find("div").eq($(".nicefood .cul").find("div").length-1))
                $("<a href='#'><p>"+tt.introduce+"</p></a>").appendTo($(".nicefood .cul").find("div").eq($(".nicefood .cul").find("div").length-1))
                if(tt.memberPrice) {
                    $("<ul><li>每件" + tt.memberPrice + "元</li></ul>").appendTo($(".nicefood .cul").find("div").eq($(".nicefood .cul").find("div").length - 1));
                    $("<li>包邮</li>").appendTo($(".nicefood .cul").find("div").eq($(".nicefood .cul").find("div").length-1).find("ul"));
                }else {
                    $("<ul><li>包邮</li></ul>").appendTo($(".nicefood .cul").find("div").eq($(".nicefood .cul").find("div").length - 1));
                }
                $("<span>￥"+tt.actualCurrentPrice+"</span>").appendTo($(".nicefood .cul").find("div").eq($(".nicefood .cul").find("div").length-1))
                $("<i class='gologin'>立即购买</i>").appendTo($(".nicefood .cul").find("div").eq($(".nicefood .cul").find("div").length-1))
            })
            $(".nicefood .cul").children("div").on("click",function () {
                var temp = $(this).index();
                window.open("html/date7.html?json=msbj.json;Index="+temp);
            })
        }
    })

    //数码家电
    $.ajax({
        url:"json/smjd.json",
        success:function (res) {
            var arrList =res.zone_data[0].showGoodsList
            arrList.forEach(function (value) {
                var tt = value.goods
                $("<div></div>").appendTo($(".digital .cul"))
                $("<a href='#'><img src="+tt.imageUrl+"></a>").appendTo($(".digital .cul").find("div").eq($(".digital .cul").find("div").length-1))
                $("<img class='scimg' src="+tt.countryCode.flagImage+">").appendTo($(".digital .cul").find("div").eq($(".digital .cul").find("div").length-1))
                $("<a href='#'><p>"+tt.title+"</p></a>").appendTo($(".digital .cul").find("div").eq($(".digital .cul").find("div").length-1))
                $("<a href='#'><p>"+tt.introduce+"</p></a>").appendTo($(".digital .cul").find("div").eq($(".digital .cul").find("div").length-1))
                if(tt.memberPrice) {
                    $("<ul><li>每件" + tt.memberPrice + "元</li></ul>").appendTo($(".digital .cul").find("div").eq($(".digital .cul").find("div").length - 1));
                    $("<li>包邮</li>").appendTo($(".digital .cul").find("div").eq($(".digital .cul").find("div").length-1).find("ul"));
                }else {
                    $("<ul><li>包邮</li></ul>").appendTo($(".digital .cul").find("div").eq($(".digital .cul").find("div").length - 1));
                }
                $("<span>￥"+tt.actualCurrentPrice+"</span>").appendTo($(".digital .cul").find("div").eq($(".digital .cul").find("div").length-1))
                $("<i class='gologin'>立即购买</i>").appendTo($(".digital .cul").find("div").eq($(".digital .cul").find("div").length-1))
            })
            $(".digital .cul").children("div").on("click",function () {
                var temp = $(this).index();
                window.open("html/date7.html?json=msbj.json;Index="+temp);
            })
        }
    })

    //点击登入事件
    $(".gologin").on("click",function () {
        $(".login").css("display","block");
        $("<i class='xxx'>X</i>").appendTo($(".login"));
        $(".allall").css("display","block")
        $(".xxx").on("click",function () {
            $(".login").css("display","none");
            $(".allall").css("display","none")
        })
    })
	
	var tempstr=$.cookie("mylogin");
    if(tempstr){
        $(".hnavl").eq(1).text(JSON.parse(tempstr).umail)
    }
	
    //固定导航栏
    $(window).on("scroll",function () {
      if(Math.abs($(this).scrollTop())> $("#preference").offset().top) {

          $("#fixednav").css("display","block").css("left",$("#nicefood").offset().left+$("#nicefood").width()+20)
      }
        if(Math.abs($(this).scrollTop())< $("#preference").offset().top) {

            $("#fixednav").css("display","none")
        }
    })

})

$("#qjtm").children("div").eq(0).find("span").on("click",function () {
    $(this).parent("div").css("display","none").siblings("div").css("display","block")
})
$("#qjtm").children("div").eq(1).find("span").on("click",function () {
    $(this).parent("div").css("display","none").siblings("div").css("display","block")
})


